package com.example.projectcode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.projectcode.mapper.StudentMapper;
import com.example.projectcode.model.Student;
import com.example.projectcode.service.StudentService;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper,Student> implements StudentService {

    @Override
    public Student selectStudent(String username, String password) {
        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",username).eq("password",password);
        Student  student= baseMapper.selectOne(queryWrapper);
        return student;
    }

    @Override
    public boolean insertStudent(Student student) {
       return baseMapper.insert(student)>0;

    }

    @Override
    public int deleteStudentById(Integer id) {
        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("Stu_id",id);
        return baseMapper.delete(queryWrapper);
    }

    @Override
    public int updateStudent(Student student) {
        UpdateWrapper<Student> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("Stu_id",student.getStuId());
        return  baseMapper.update(student,updateWrapper);


    }

    @Override
    public List<Student> selectAllStudents() {
        return baseMapper.selectList(new QueryWrapper<Student>());
    }

//    @Override
//    public List<Student> selectAllStudents(Long page, Long size) {
//        Page<Student> studentPage = new Page<>(page,size);
//
//        List<Student>  studentList = baseMapper.selectPage(studentPage,null).getRecords();
//
//       return studentList;
//
//    }


}
